// WGetOpt.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "getopt.h"

int test_getopt(int, _TCHAR **);
int test_getopt_long(int, _TCHAR **);
int test_getopt_long_only(int, _TCHAR **);

int _tmain(int argc, _TCHAR* argv[]) {
    int ret = 0;

    ret = test_getopt(argc, argv);

    return ret;
}

int test_getopt(int argc, _TCHAR *argv[] ) {

 	TCHAR opt_inc_fflag = 0, opt_inc_dflag = 0;
	TCHAR opt_exc_fflag = 0, opt_exc_dflag = 0;
	TCHAR *opt_inc_fval = NULL, *opt_inc_dval = NULL;
	TCHAR *opt_exc_fval = NULL, *opt_exc_dval = NULL;
	TCHAR opt_src_dflag = 0, opt_des_dflag = 0;
    TCHAR *opt_src_dval = NULL, *opt_des_dval = NULL;
	
	int c = EOF;
	int i = 0;

     while (EOF != (c = getopt(argc, argv, _T("s:t:F:f:D:d:")))) {
		switch (c) {
			case 'f':
				opt_inc_fflag = 1;
				opt_inc_fval = optarg;
				break;
			case 'F':
				opt_exc_fflag = 1;
				opt_exc_fval = optarg;
				break;
			case 'd':
				opt_inc_dflag = 1;
				opt_inc_dval = optarg;
				break;
			case 'D':
				opt_exc_dflag = 1;
				opt_exc_dval = optarg;
				break;
			case 's':
				opt_src_dflag = 1;
				opt_src_dval = optarg;
				break;
            case 't':
                opt_des_dflag = 1;
                opt_des_dval = optarg;
                break;
			case '?':
				_tprintf(_T("Unknown the option '-%c'.\n"), optopt);
				return 1;
			default:
				return 2;
        }
    }


#if _DEBUG
    _tprintf(_T("opt_src_dflag = %d opt_src_dval = %s\n"), opt_src_dflag, opt_src_dval);
    _tprintf(_T("opt_des_dflag = %d opt_des_dval = %s\n"), opt_des_dflag, opt_des_dval);
    _tprintf(_T("opt_inc_fflag = %d opt_inc_fval = %s\n"), opt_inc_fflag, opt_inc_fval);
    _tprintf(_T("opt_exc_fflag = %d opt_exc_fval = %s\n"), opt_exc_fflag, opt_exc_fval);
    _tprintf(_T("opt_inc_dflag = %d opt_inc_dval = %s\n"), opt_inc_dflag, opt_inc_dval);
    _tprintf(_T("opt_exc_dflag = %d opt_exc_dval = %s\n"), opt_exc_dflag, opt_exc_dval);

		for (i = optind; i < argc; i++)
			_tprintf(_T("Non-option argument %s\n"), argv[i]);
#endif

	return 0;
}

int test_getopt_long(int argc, _TCHAR *argv[] ) {

 	TCHAR opt_inc_fflag = 0, opt_inc_dflag = 0;
	TCHAR opt_exc_fflag = 0, opt_exc_dflag = 0;
	TCHAR *opt_inc_fval = NULL, *opt_inc_dval = NULL;
	TCHAR *opt_exc_fval = NULL, *opt_exc_dval = NULL;
	TCHAR opt_src_dflag = 0, opt_des_dflag = 0;
    TCHAR *opt_src_dval = NULL, *opt_des_dval = NULL;
	
	int c = EOF;
	int i = 0;
    

    while (EOF != (c = getopt(argc, argv, _T("s:t:F:f:D:d:")))) {
		switch (c) {
			case 'f':
				opt_inc_fflag = 1;
				opt_inc_fval = optarg;
				break;
			case 'F':
				opt_exc_fflag = 1;
				opt_exc_fval = optarg;
				break;
			case 'd':
				opt_inc_dflag = 1;
				opt_inc_dval = optarg;
				break;
			case 'D':
				opt_exc_dflag = 1;
				opt_exc_dval = optarg;
				break;
			case 's':
				opt_src_dflag = 1;
				opt_src_dval = optarg;
				break;
            case 't':
                opt_des_dflag = 1;
                opt_des_dval = optarg;
                break;
			case '?':
				_tprintf(_T("Unknown the option '-%c'.\n"), optopt);
				return 1;
			default:
				return 2;
        }
    }


#if _DEBUG
    _tprintf(_T("opt_src_dflag = %d opt_src_dval = %s\n"), opt_src_dflag, opt_src_dval);
    _tprintf(_T("opt_des_dflag = %d opt_des_dval = %s\n"), opt_des_dflag, opt_des_dval);
    _tprintf(_T("opt_inc_fflag = %d opt_inc_fval = %s\n"), opt_inc_fflag, opt_inc_fval);
    _tprintf(_T("opt_exc_fflag = %d opt_exc_fval = %s\n"), opt_exc_fflag, opt_exc_fval);
    _tprintf(_T("opt_inc_dflag = %d opt_inc_dval = %s\n"), opt_inc_dflag, opt_inc_dval);
    _tprintf(_T("opt_exc_dflag = %d opt_exc_dval = %s\n"), opt_exc_dflag, opt_exc_dval);

		for (i = optind; i < argc; i++)
			_tprintf(_T("Non-option argument %s\n"), argv[i]);
#endif

    return 0;
}


